﻿using MediatR;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Domain.SheepFarmSetting;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.SheepFarmsetup
{
    public class SheepFarmsetupCreateHandler : IRequestHandler<SheepFarmsetupCreateCommon, Result>
    {
        public readonly IBaseRepository<Sheepfarm> SheepfarmRepository;

        public SheepFarmsetupCreateHandler(IBaseRepository<Sheepfarm> sheepfarmRepository)
        {
            SheepfarmRepository = sheepfarmRepository;
        }

        public async Task<Result> Handle(SheepFarmsetupCreateCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var result = new Sheepfarm()
                {
                    SheepfarmName = request.SheepfarmName,
                    SheepfarmSimpleName = request.SheepfarmSimpleName,
                    SheepfarmscaleId = request.SheepfarmscaleId,
                    ProviceId = request.ProviceId,
                    CityId = request.CityId,
                    CountyId = request.CountyId,
                    Fulladdress = request.Fulladdress,
                    CreateBooksDate = request.CreateBooksDate,
                    SheepfarmHead = request.SheepfarmHead,
                    DepartmentId = request.DepartmentId,
                    IsOpen = request.IsOpen
                };
                SheepfarmRepository.Add(result);
                res.Code = (int)CommonEnumCode.success;
                res.Msg = "羊场设置表新增";
            }
            catch (Exception)
            {

                throw;
            }

            return res;
        }
    }
}
